//
//  HDSettingViewController.m
//  HDLianXuDingWeiDemo
//
//  Created by HDHaoShaoPeng on 2017/5/12.
//  Copyright © 2017年 HDHaoShaoPeng. All rights reserved.
//

#import "HDSettingViewController.h"

@interface HDSettingViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *myTF;
@property (weak, nonatomic) IBOutlet UITextView *textView;

@end

@implementation HDSettingViewController

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    if (self.machineString) {
        [self showMachineStringWith:self.machineString];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark - TextField Delegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.myTF resignFirstResponder];
    return YES;
}

#pragma mark - 私有方法

-(void)showAlertWithMessage:(NSString *)message
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:action];
    
    
    [self presentViewController:alert animated:YES completion:nil];
    
}



#pragma mark - 外部调用方法

-(void)showMachineStringWith:(NSString *)string
{
    dispatch_async(dispatch_get_main_queue(), ^{
        self.myTF.text = string;
    });
}

-(void)showMessagesWith:(NSString *)message
{
    dispatch_async(dispatch_get_main_queue(), ^{
        self.textView.text = message;
    });
}


#pragma mark - 点击方法

- (IBAction)settingClicked:(id)sender {
    if (self.myTF.text.length > 0) {
        [self.myDelegate machineStringBackWith:self.myTF.text];
        [self showAlertWithMessage:@"设置成功!"];
    }
    else
    {
        [self showAlertWithMessage:@"标识符不能为空。"];
    }
}


- (IBAction)backClicked:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}



@end
















